package com.lanbu.system.service.impl;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanbu.common.config.LanBuConfig;
import com.lanbu.common.core.domain.entity.SysUser;
import com.lanbu.common.utils.file.FileUploadUtils;
import com.lanbu.system.domain.dto.EmotionAnalysisDTO;
import com.lanbu.system.domain.vo.EmotionAnalysisResultsChartVo;
import com.lanbu.system.domain.vo.EmotionAnalysisResultsVo;
import com.lanbu.system.domain.vo.EmotionAnalysisResultsVoList;
import com.lanbu.system.domain.vo.ListAddressChart;
import com.lanbu.system.service.ISysUserService;
import com.lanbu.system.utils.CustomMultipartFile;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lanbu.system.mapper.EmotionAnalysisResultsMapper;
import com.lanbu.system.domain.EmotionAnalysisResults;
import com.lanbu.system.service.IEmotionAnalysisResultsService;

/**
 * 情绪分析结果Service业务层处理
 * 
 * @author lanbu
 * @date 2024-11-23
 */
@Service
public class EmotionAnalysisResultsServiceImpl extends ServiceImpl<EmotionAnalysisResultsMapper,EmotionAnalysisResults> implements IEmotionAnalysisResultsService
{
    @Autowired
    private EmotionAnalysisResultsMapper emotionAnalysisResultsMapper;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询情绪分析结果
     * 
     * @param id 情绪分析结果主键
     * @return 情绪分析结果
     */
    @Override
    public EmotionAnalysisResults selectEmotionAnalysisResultsById(Long id)
    {
        return emotionAnalysisResultsMapper.selectEmotionAnalysisResultsById(id);
    }

    /**
     * 查询情绪分析结果列表
     * 
     * @param emotionAnalysisResults 情绪分析结果
     * @return 情绪分析结果
     */
    @Override
    public List<EmotionAnalysisResultsVoList> selectEmotionAnalysisResultsList(EmotionAnalysisDTO emotionAnalysisResults)
    {
        List<EmotionAnalysisResultsVoList> emotionAnalysisResultsList= emotionAnalysisResultsMapper.selectEmotionAnalysisResultsList(emotionAnalysisResults);
//        for (int i = 0; i < emotionAnalysisResultsList.size(); i++) {
//
//            EmotionAnalysisResultsVoList  emotionAnalysisResults1= emotionAnalysisResultsList.get(i);
//            EmotionAnalysisResults analysisResults=new EmotionAnalysisResults();
//
//            BeanUtils.copyProperties(emotionAnalysisResults1,analysisResults);
//            if (analysisResults.getUrl()==null&&analysisResults.getImageBase64()!=null){
//                // 解码Base64字符串为字节数组
//                byte[] decodedBytes = Base64.getDecoder().decode(analysisResults.getImageBase64());
//
//                // 创建MockMultipartFile对象
//                CustomMultipartFile multipartFile = new CustomMultipartFile(
//                        decodedBytes,
//                        analysisResults.getName()+analysisResults.getStudent()+".jpeg",
//                        analysisResults.getName()+analysisResults.getStudent()+".jpeg",
//                        "text/plain"
//                );
//                //                // 上传文件路径
//                String filePath1 = LanBuConfig.getUploadPath();
////                // 上传并返回新文件名称
//                try {
//                    String fileName1 = FileUploadUtils.upload(filePath1, multipartFile);
//
//                    analysisResults.setUrl(fileName1);
//                    emotionAnalysisResultsMapper.updateEmotionAnalysisResults(analysisResults);
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//
//            }
//
//        }





        return emotionAnalysisResultsList;
    }

    /**
     * 新增情绪分析结果
     * 
     * @param emotionAnalysisResults 情绪分析结果
     * @return 结果
     */
    @Override
    public int insertEmotionAnalysisResults(EmotionAnalysisResults emotionAnalysisResults)
    {
        return emotionAnalysisResultsMapper.insert(emotionAnalysisResults);
    }

    /**
     * 修改情绪分析结果
     * 
     * @param emotionAnalysisResults 情绪分析结果
     * @return 结果
     */
    @Override
    public int updateEmotionAnalysisResults(EmotionAnalysisResults emotionAnalysisResults)
    {
        return emotionAnalysisResultsMapper.updateEmotionAnalysisResults(emotionAnalysisResults);
    }

    /**
     * 批量删除情绪分析结果
     * 
     * @param ids 需要删除的情绪分析结果主键
     * @return 结果
     */
    @Override
    public int deleteEmotionAnalysisResultsByIds(List<Long> ids)
    {
        return emotionAnalysisResultsMapper.deleteBatchIds(ids);
    }

    @Override
    public int deleteEmotionAnalysisResultsByIP(String ips) {
        return emotionAnalysisResultsMapper.deleteEmotionAnalysisResultsByIP(ips);
    }

    /**
     * 删除情绪分析结果信息
     * 
     * @param id 情绪分析结果主键
     * @return 结果
     */
    @Override
    public int deleteEmotionAnalysisResultsById(Long id)
    {
        return emotionAnalysisResultsMapper.deleteById(id);
    }

    @Override
    public List<EmotionAnalysisResultsVo> selectEmotionAnalysisResultsListUser(EmotionAnalysisResultsVo emotionAnalysisResults) {
        return  emotionAnalysisResultsMapper.selectEmotionAnalysisResultsListUser(emotionAnalysisResults);
    }

    @Override
    public List<EmotionAnalysisResultsChartVo> selectEmotionAnalysisResultsListUserChart(EmotionAnalysisDTO emotionAnalysisDTO) {

        List<EmotionAnalysisResultsChartVo> emotionAnalysisResultsVos = emotionAnalysisResultsMapper.selectEmotionAnalysisResultsListUserChart(emotionAnalysisDTO);


        return emotionAnalysisResultsVos;
    }

    @Override
    public List<ListAddressChart> selectEmotionAnalysisResultsListAddressChart(EmotionAnalysisDTO emotionAnalysisDTO) {
        return emotionAnalysisResultsMapper.selectEmotionAnalysisResultsListAddressChart(emotionAnalysisDTO);
    }

    /**
     * 查询情绪分析结果列表
     *
     * @param emotionAnalysisResults 情绪分析结果
     * @return 情绪分析结果
     */
    @Override
    public List<EmotionAnalysisResultsVoList> selectEmotionAnalysisResultsListFocus(EmotionAnalysisDTO emotionAnalysisResults)
    {
        List<EmotionAnalysisResultsVoList> emotionAnalysisResultsList= emotionAnalysisResultsMapper.selectEmotionAnalysisResultsListFocus(emotionAnalysisResults);
//        for (int i = 0; i < emotionAnalysisResultsList.size(); i++) {
//
//            EmotionAnalysisResultsVoList  emotionAnalysisResults1= emotionAnalysisResultsList.get(i);
//            EmotionAnalysisResults analysisResults=new EmotionAnalysisResults();
//
//            BeanUtils.copyProperties(emotionAnalysisResults1,analysisResults);
//            if (analysisResults.getUrl()==null&&analysisResults.getImageBase64()!=null){
//                // 解码Base64字符串为字节数组
//                byte[] decodedBytes = Base64.getDecoder().decode(analysisResults.getImageBase64());
//
//                // 创建MockMultipartFile对象
//                CustomMultipartFile multipartFile = new CustomMultipartFile(
//                        decodedBytes,
//                        analysisResults.getName()+analysisResults.getStudent()+".jpeg",
//                        analysisResults.getName()+analysisResults.getStudent()+".jpeg",
//                        "text/plain"
//                );
//                //                // 上传文件路径
//                String filePath1 = LanBuConfig.getUploadPath();
////                // 上传并返回新文件名称
//                try {
//                    String fileName1 = FileUploadUtils.upload(filePath1, multipartFile);
//
//                    analysisResults.setUrl(fileName1);
//                    emotionAnalysisResultsMapper.updateEmotionAnalysisResults(analysisResults);
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//
//            }
//
//        }





        return emotionAnalysisResultsList;
    }

    @Override
    public List<EmotionAnalysisResultsVoList> selectEmotionAnalysisResultsListUnknown(EmotionAnalysisDTO emotionAnalysisResults) {
        return emotionAnalysisResultsMapper.selectEmotionAnalysisResultsListUnknown(emotionAnalysisResults);
    }
}
